import 'package:cbec_app/components/base/base_chekbox.dart';
import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/base/base_nav_bar.dart';
import 'package:cbec_app/components/base/base_page.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/order/after_goods_item.dart';
import 'package:cbec_app/components/popup/question_descript.dart';
import 'package:cbec_app/components/popup/refund_reason_popup.dart';
import 'package:cbec_app/pages/my/controller/after_pop_ctr.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class Tuikuan extends StatelessWidget {
  final AfterPopController afterPopCtr = Get.put(AfterPopController());

  Tuikuan({super.key});

  @override
  Widget build(BuildContext context) {
    return BasePage(
      title: afterPopCtr.pageTitle.value,
      iconType: IconType.back,
      children: [
        Container(
          decoration: border_radis(Colors.white),
          margin: EdgeInsets.fromLTRB(8.w, 4.w, 8.w, 10.w),
          padding: EdgeInsets.all(10.w),
          child: ListView.builder(
              itemCount: afterPopCtr.goodsList.length,
              shrinkWrap: true,
              itemBuilder: (context, index) {
                return AfterGoodsItem(showCheckBox: false, item: afterPopCtr.goodsList[index]['item'], showAdd: false);
              }),
        ),
        Container(
          decoration: border_radis(Colors.white),
          margin: EdgeInsets.only(left: 8.w, right: 8.w),
          padding: EdgeInsets.only(left: 10.w, right: 10.w, top: 10.w),
          child: Column(
            children: [
              listItem(
                  context,
                  "申请原因*",
                  Row(
                    children: [Obx(() => Text(afterPopCtr.reasonTextd.value, style: setTextStyle(14, FontWeight.w300, Tools.fromHex("#999999")))), Icon(Icons.chevron_right, color: Tools.fromHex("#999999"))],
                  ),
                  type: 1),
              listItem(
                  context,
                  "问题描述与上传凭证",
                  Row(
                    children: [Text("上传有助于处理问题", style: setTextStyle(14, FontWeight.w300, Tools.fromHex("#999999"))), Icon(Icons.chevron_right, color: Tools.fromHex("#999999"))],
                  ),
                  type: 2),
              afterPopCtr.type == 1 ? listItem(context, "退款金额", Text("￥${afterPopCtr.data['priceOrder']}", style: setTextStyle(14, FontWeight.w300, Tools.fromHex("#333333")))) : const SizedBox()
            ],
          ),
        ),
        //如果积分足够的话、 就显示这里
        afterPopCtr.type == 1
            ? Container(
                decoration: border_radis(Colors.white),
                height: 50.h,
                padding: EdgeInsets.fromLTRB(8.w, 10.w, 8.w, 5.w),
                margin: EdgeInsets.fromLTRB(10.w, 15.w, 10.w, 4.w),
                child: Row(
                    // children: [
                    //   Text("当前可用积分",
                    //       style: setTextStyle(
                    //           14, FontWeight.w300, Tools.fromHex("#000000"))),
                    //   Text(afterPopCtr.membership_ata['points'].toString()+'',
                    //       style: setTextStyle(
                    //           14, FontWeight.w300, Tools.fromHex("#F83F2D"))),
                    //   Text("售后需扣除可用积分",
                    //       style: setTextStyle(
                    //           14, FontWeight.w300, Tools.fromHex("#000000"))),
                    //   Text('0',
                    //       style: setTextStyle(
                    //           14, FontWeight.w300, Tools.fromHex("#F83F2D")))
                    // ],
                    ),
              )
            : const SizedBox(),
        //积分不够的话，就显示这里
        afterPopCtr.type == 1
            ? Container(
                decoration: border_radis(Colors.white),
                padding: EdgeInsets.fromLTRB(8.w, 10.w, 8.w, 5.w),
                margin: EdgeInsets.fromLTRB(10.w, 15.w, 10.w, 4.w),
                child: listItem(context, "是否同意购买积分", BaseCheckBox(value: false), hasBorder: false),
              )
            : const SizedBox(),
        afterPopCtr.type == 1 ? descriptTxt() : const SizedBox(),
        //按钮
        Positioned(
            key: GlobalKey(debugLabel: 'Positioned'),
            bottom: MediaQuery.of(context).padding.bottom,
            child: Container(
              color: Colors.white,
              padding: EdgeInsets.fromLTRB(18.w, 5.w, 18.w, 5.w),
              width: 375.w,
              child: solidButton("提交", () {
                afterPopCtr.submit();
              }),
            ))
      ],
    );
  }

  Widget listItem(BuildContext context, String txt, Widget right, {bool? hasBorder = true, int? type = 0}) {
    return BaseInteractive(
      onClick: () {
        switch (type) {
          case 1:
            refundReasonPopup(context);
            break;
          case 2:
            questionDescriptPopup(context);
            break;
          default:
        }
      },
      childWidget: Container(
        decoration: hasBorder == true ? bottom_gary_border : null,
        padding: EdgeInsets.fromLTRB(0.w, 15.w, 0.w, 20.w),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [Text(txt, style: setTextStyle(14, FontWeight.w300, Tools.fromHex("#000000"))), right],
        ),
      ),
    );
  }

  ///富文本描述
  Widget descriptTxt() {
    TextStyle maintxt = setTextStyle(12, FontWeight.w300, Tools.fromHex("#999999"));
    TextStyle pointTxt = setTextStyle(12, FontWeight.w300, Tools.fromHex("#F83F2D"));

    return Container(
        padding: EdgeInsets.only(left: 8.w, right: 8.w),
        child: RichText(
          text: TextSpan(
            text: '例：当前可用积分',
            style: maintxt,
            children: <TextSpan>[
              // TextSpan(text: afterPopCtr.membership_ata['points'].toString(), style: pointTxt),
              TextSpan(text: '100', style: pointTxt),
              TextSpan(text: '售后需扣除可用积分', style: maintxt),
              // TextSpan(text: (afterPopCtr.membership_ata['points'] + 20).toString(), style: pointTxt),
              TextSpan(text: '120', style: pointTxt),
              TextSpan(text: '需要购买', style: maintxt),
              TextSpan(
                text: '20',
                style: pointTxt,
              ),
              TextSpan(text: '积分才可申请退款购买积分金额将直接扣减退款金额 ', style: maintxt),
            ],
          ),
        ));
  }
}
